package com.icez.calendar_view

import android.content.Context
import android.util.Log
import androidx.recyclerview.widget.GridLayoutManager
import com.icez.base_util_library.adapter.CalendarViewAdapter
import com.icez.calendar_view.databinding.ItemCalendarPagerBinding

class CalendarPagerAdapter(
    layoutResId: Int,
    mData: ArrayList<CalendarModel>,
    val mCalendarViewConfig: CalendarViewConfig
):CalendarViewAdapter<CalendarModel,ItemCalendarPagerBinding>(layoutResId,mData) {
    var mOnDayItemClickListener: CalendarView.OnDayItemClickListener? = null
    var mOnDayRangeListener: CalendarView.OnDayRangeListener ?= null
    override fun onBusinessOperation(
        context: Context,
        binding: ItemCalendarPagerBinding,
        position: Int,
        item: CalendarModel?
    ) {
        binding.itemCalendarDayRv.layoutManager = GridLayoutManager(context,7)
        val mCalendarDayAdapter =
            item?.monthDay?.let { CalendarDayAdapter(R.layout.item_calendar_day, it,item.year,item.month,mCalendarViewConfig,{
                notifyItemChanged(position)
                mOnDayItemClickListener?.dayItemClick(item.year.toInt(),item.month.toInt(),(it?:"0").toInt())
            }){
                mOnDayRangeListener?.dayRange(mCalendarViewConfig.startRangeDate,mCalendarViewConfig.endRangeDate)
            } }
        binding.itemCalendarDayRv.adapter = mCalendarDayAdapter
    }
}